//版本更新
	function version(){
		var launchFlag = plus.storage.getItem("launchFlag");
		if(launchFlag=="true") {
			plus.runtime.getProperty(plus.runtime.appid,function(inf){
				wgtVer=inf.version;
				var uuid = plus.device.uuid;
				if(mui.os.ios){
					var type = 2;//IOS
					//console.log("当前应用版本："+wgtVer);
				}else{
					var type = 1;//安卓
				}
				var res = get_ajax_no_token('version_index','post',{uuid:uuid,type:type,wgtVer:wgtVer});
				console.log(JSON.stringify(res));
				console.log("当前应用版本："+wgtVer);
				//checkUpdate(wgtVer);
			});
		} 
		
	}
	function checkUpdate(wgtVer){
		var data = ''; 
		var res = request_ajax_no_token(getVersion,'GET',data);
		if(res.code == 1){
			if(res.data.version > wgtVer){
				wgtUrl = domain+'/upload/'+ res.data.path;
				mui.confirm('更新到新版本？', ['取消','确定'], function(){
						downWgt(8,wgtUrl);  // 下载升级包
					},function(){
					console.log('取消后执行...');
					return false; 
				});  
			}
		}
	};
	function downWgt(apksize,wgtUrl){
		wgtWaiting = plus.nativeUI.showWaiting("开始下载");
		var wgtOption = { filename: "update/", retry: 1 };
		var task = plus.downloader.createDownload(wgtUrl, {}, function (download, status) {
			if (status == 200) {
				wgtWaiting.setTitle("开始安装");
				installWgt(download.filename);
			} else {
				mui.alert("应用升级失败！");
				wgtWaiting.close();
			}
		});
		task.addEventListener("statechanged", function (download, status) {
			switch (download.state) {
				case 2:
					wgtWaiting.setTitle("已连接到服务器");
					break;
				case 3:
					var percent = download.downloadedSize/apksize * 100;
					//console.log(parseInt(percent));
					percent=percent.toFixed(2); 
					wgtWaiting.setTitle("已下载 " + parseInt(percent) + "%");
									//wgtWaiting.setTitle("下载中");
					break;
				case 4:
					wgtWaiting.setTitle("下载完成");
					break;
			}
		});
		task.start();
	}
	// 更新应用资源
	function installWgt(path){
		plus.nativeUI.showWaiting("正在安装升级...");
		plus.runtime.install(path,{},function(){
			plus.nativeUI.closeWaiting();
			plus.nativeUI.alert("升级包更新完成！",function(){
				plus.runtime.restart();
			});
		},function(e){
			plus.nativeUI.closeWaiting();
			//console.log("升级包文件失败["+e.code+"]："+e.message);
			plus.nativeUI.alert("升级包文件更新失败");
		});
	}